function oil = oil_single_subject_maps(oil)

if ~isdir([oil.name '/ica_dir/single_subject_maps/']),mkdir([oil.name '/ica_dir/single_subject_maps/']); end
% Get ICA results
try
    group_spat_map=oil.ica.mixing_matrix;
    tc=oil.ica.tICs;
    subj_ind=oil.ica.subj_ind;
catch
    error('Unable to find all the relevant ICA information');
end
% Get ICA input data
ica_concat=[];
for i=1:length(oil.ica.ica_concat_path)
    try
        xall=load([oil.ica.ica_concat_path{i} '.mat']);
        xall=xall.ica_concat;
        ica_concat=[ica_concat; xall];
    catch
        xall=nii_quickread([oil.name '/ica_dir/' oil.concat_subs.concat_file],oil.ica.gridstep);
        ica_concat=[ica_concat; xall];
    end
end

Nsubs=length(subj_ind)-1;
Nvoxels = size(ica_concat,1);
Nics = oil.ica.num_ics;

% set-up design matrix (identity).
for i=1:size(group_spat_map,2)
    con{i}=(1:size(group_spat_map,2)==i)';
end

for subnum=1:Nsubs;
    
    sing_sub_dat=ica_concat(:,subj_ind(subnum):subj_ind(subnum+1)-1);
    sing_sub_tc=normalise(tc(:,subj_ind(subnum):subj_ind(subnum+1)-1))';
        
    copeout=zeros(Nvoxels,Nics);varcopeout=zeros(Nvoxels,Nics);coapeout=zeros(Nvoxels,Nics);dof=zeros(Nvoxels,Nics);peout=zeros(Nvoxels,Nics);

    for v=1:Nvoxels 
        y=sing_sub_dat(v,:)';
        x=sing_sub_tc;
        pinvxtx=pinv(x'*x);
        pinvx=pinv(x);
        [copeout(v,:), varcopeout(v,:), coapeout(v,:), dof(v,:),peout(v,:)]=glm_fast_for_meg(y,x,pinvxtx,pinvx,con,0);
    end
    
    cope_files{subnum} = [oil.name '/ica_dir/single_subject_maps/ica_copes_' oil.enveloping.source_space_envelopes_results_fnames{subnum}];
    nii_quicksave(copeout,cope_files{subnum},oil.ica.gridstep);
    tstat_files{subnum} = [oil.name '/ica_dir/single_subject_maps/ica_tstats_' oil.enveloping.source_space_envelopes_results_fnames{subnum}];
    nii_quicksave(copeout./sqrt(varcopeout),tstat_files{subnum},oil.ica.gridstep);
end

oil.ica_first_level.cope_files = cope_files;
oil.ica_first_level.tstat_files = tstat_files;
